#include "recursion/factorial.h"

int fact(const int n)
{
    if (n < 0)
        throw "invalid param";
    if (0 == n || 1 == n)
        return 1;
    else
        return n * fact(n - 1);
}

int factLoop(const int n)
{
    if (n < 0)
        return -1;
    if (0 == n || 1 == n)
        return 1;

    int result = 1;
    for (int i = 2; i <= n; i++)
    {
        result = result * i;
    }

    return result;
}